<?php

namespace App\Jobs\Category;

use App\Jobs\Helper as JobHelper;
use App\Models\Category;
use Illuminate\Bus\Queueable;
use Illuminate\Http\Request;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class Query implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, JobHelper;

    protected $request;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($request = null, $isPage=false, $pageSize=15)
    {
        $this->request = $request;
        $this->isPage = $isPage;
        $this->pageSize = $pageSize;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $res = Category::whereParentId(0)->with('parent')->orderBy('sort');

        return ($this->isPage) ? $res->paginate($this->pageSize) : $res->get();
    }

}
